<?php use PHPCI\Helper\Lang; ?>

<?php if(empty($builds) || !count($builds)): ?>
	<tr class="">
		<td colspan="6"><?php Lang::out('no_builds_yet'); ?></td>
	</tr>
<?php endif; ?>

<?php foreach($builds as $build): ?>

<?php
switch($build->getStatus())
{
	case 0:
		$cls = 'active';
		$subcls = 'info';
		$status = Lang::get('pending');

	break;

	case 1:
		$cls = 'warning';
		$subcls = 'warning';
		$status = Lang::get('running');
	break;

	case 2:
		$cls = 'success';
		$subcls = 'success';
		$status = Lang::get('success');
	break;

	case 3:
		$cls = 'danger';
		$subcls = 'danger';
		$status = Lang::get('failed');
	break;
}
?>
<tr class="<?php print $cls; ?>">
	<td><a href="<?php echo PHPCI_URL ?>build/view/<?php print $build->getId(); ?>">#<?php print str_pad($build->getId(), 6, '0', STR_PAD_LEFT); ?></a></td>
    <td><?php print $build->getCreated()->format('Y-m-d H:i:s'); ?></td>
	<td><a href="<?php echo PHPCI_URL ?>project/view/<?php print $build->getProjectId(); ?>">
            <i class="fa fa-<?php print $build->getProject()->getIcon(); ?>"></i>

            <?php
            if (is_object($build->getProject())) {
                print htmlspecialchars($build->getProject()->getTitle());
            } else {
                print ' - ';
            }
        ?></a></td>

    <td class="hidden-md hidden-sm hidden-xs">
        <?php
            if ($build->getCommitId() !== 'Manual') {
                print sprintf(
                    '<a href="%s" target="_blank">%s (%s)</a>',
                    $build->getCommitLink(),
                    substr($build->getCommitId(), 0, 7),
                    $build->getCommitterEmail()
                );
            } else {
                print Lang::get('manual_build');
            }
        ?>
    </td>

	<td><a href="<?php print $build->getBranchLink(); ?>" target="_blank"><?php print $build->getBranch(); ?></a></td>
	<td>
		<span class='label label-<?php echo $subcls ?>'><?php echo $status ?></span>
	</td>
	<td>
		<div class="btn-group">
			<a class="btn btn-default btn-sm" href="<?php echo PHPCI_URL ?>build/view/<?php print $build->getId(); ?>"><?php Lang::out('view'); ?></a>
			<?php if($this->User()->getIsAdmin()): ?>
			<button class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
				<span class="caret"></span>
			</button>
			<ul class="dropdown-menu">
				<li><a href="<?php echo PHPCI_URL ?>build/delete/<?php print $build->getId(); ?>" class="phpci-app-delete-build"><?php Lang::out('delete_build'); ?></a></li>
			</ul>
			<?php endif; ?>
		</div>
	</td>
</tr>
<?php endforeach; ?>
